//
//  NSString+HMTimeString.m
//  springFlowers
//
//  Created by qu on 2017/1/4.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "NSString+HMTimeString.h"

@implementation NSString (HMTimeString)

+ (instancetype)getTimeWithString:(NSString *)timeStr {
    
    if ([timeStr isEqualToString:@"-1"]) {
        return [NSString stringWithFormat:@"音频时长:59分59秒"];
    } else if ( timeStr == nil) {
        return [NSString stringWithFormat:@"音频时长:1分30秒"];
    }
    
    NSInteger timeVaule = [timeStr integerValue];
    
    NSInteger hour = timeVaule / 3600 ;
    NSInteger minute = timeVaule % 3600 / 60;
    NSInteger sec = timeVaule % 3600 % 60 %60;
    
    if (hour != 0 ) {
        return [NSString stringWithFormat:@"音频时长:%zd小时%zd分%zd秒",hour,minute,sec];
    } else {
        
        return [NSString stringWithFormat:@"音频时长:%zd分%zd秒",minute,sec];
    }
}

+ (instancetype)getSavingTimeWithString:(NSString *)timeStr{
    if ([timeStr isEqualToString:@"-1"]) {
        return [NSString stringWithFormat:@"解读版：平均节省0小时阅读时间"];
    } else if ( timeStr == nil) {
        return [NSString stringWithFormat:@"解读版：平均节省0小时阅读时间"];
    }
    
        return [NSString stringWithFormat:@"解读版：平均节省%d小时阅读时间",timeStr.intValue];
}


+ (NSString *)convertTime:(CGFloat)second{
    NSDate *d = [NSDate dateWithTimeIntervalSince1970:second];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    if (second/3600 >= 1) {
        [formatter setDateFormat:@"HH:mm:ss"];
    } else {
        [formatter setDateFormat:@"mm:ss"];
    }
    NSString *showtimeNew = [formatter stringFromDate:d];
    return showtimeNew;
}

+ (NSString *)convertMin:(CGFloat)sec
{
    NSInteger tMin = (NSInteger)sec / 60;
    NSInteger tSec = (NSInteger)sec % 60;
    return [NSString stringWithFormat:@"%02ld:%02ld",tMin,tSec];
}

+ (NSString *)getAddTimeForDate:(NSInteger)addTime {
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"M月dd日";
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:addTime];
    return [formatter stringFromDate:date];
}

+ (NSString *)getAddDayForDate:(NSInteger)addTime {
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"dd日";
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:addTime];
    return [formatter stringFromDate:date];
}

@end
